home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / stuffit.arc / GETFIRST.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-11-18  |  4.4 KB  |  167 lines

  1. ;GETFIRST.ASM
  2.  
  3. ;6.12.85
  4. ;4.29.85
  5. ;Hack of LIST547.ASM by Vern Buerg
  6.  
  7. comment ~
  8.  
  9.         Open the first matching file
  10.  
  11. On entry:
  12.     
  13.  
  14. Uses:
  15.     dta2        address of working dta
  16.     dpathfilenm    ASCIIZ string from cmdline, w/*.* if any
  17.     dpathfilenm_len    length of ASCIIZ string, w/o trailing zero
  18.  
  19. Error codes if CY set:
  20.     2    File not found
  21.     18    No more files
  22.     
  23.  
  24. Writes to:
  25.  
  26.         fileptr        2 bytes before file name
  27.  
  28. Equates defined in PSPEQU.ASM:
  29.  
  30. psp_dta         equ     80H     ;80H-FFH;Default disk transfer area (128 bytes)
  31. psp_cmlin_tail  equ     80H             ;Command line tail
  32. psp_dta_res     equ     80H     ;80H-94H;21 reserved bytes for next find call
  33. psp_dta_fattr   equ     95H     ;95H    ;attribute found (1 byte)
  34. psp_dta_ftime   equ     96H     ;96H-97H;file's time (2 bytes)
  35. psp_dta_fdate   equ     98H     ;98H-99H;file's date (2 bytes)
  36. psp_dta_fsizlw  equ     9AH     ;9AH-9BH;file's size - low word (2 bytes)
  37. psp_dta_fsizhw  equ     9CH     ;9CH-9DH;file's size - high word (2 bytes)
  38. psp_dta_fnamext equ     9EH     ;9EH-A9H;file name.ext, no blanks (12 bytes)
  39. psp_dta_fnxtzer equ     AAH     ;AAH    ;trailing zero, to make ASCIIZ (1 byte)
  40.  
  41. ~       
  42.  
  43. ;----------------------------------------------------------
  44. ;        constants and messages
  45.  
  46. newline        db    cr,lf,eos
  47. gf_msg        db    cr,lf,'getfirst: ',eos
  48. gn_msg        db    cr,lf,'getnext: ',eos
  49.  
  50. GETNEXT:                                ;Second entry point--for next file
  51. ;Note: not 3.0, which requires setting DS:DX
  52.   
  53.             mov     dx,offset dta2          ;Reset DTA...bashed by EXEC
  54.         mov    ah,1ah            ;set DTA function call
  55.             int     21h
  56.         jc    gn_err        
  57.  
  58.             mov     ah,4FH                  ;Find Next call
  59.             int     21H
  60.         jc    gn_err
  61.         mov     si,fileptr              ;set ptr to drop in found name
  62.             jmp     getnext2                ;now continue with file ops
  63.  
  64. gn_err:
  65.         push    ax            ;save error code
  66.         mov    dx,offset gn_msg
  67.         mov    ah,9h            ;print string function call
  68.         int    21h            ;ignore err ret, if any
  69.         pop    ax            ;restore error code
  70.         call    errmsg
  71.         stc
  72.         ret 
  73.  
  74. GETFIRST    proc    near
  75.  
  76.         mov     dx,offset dta2      ;Reset DTA...bashed by EXEC
  77.         mov    ah,1ah            ;set DTA function call
  78.         int    21h
  79.         jnc    gf1
  80.         jmp    gf_err_xit        
  81.  
  82. gf1:            mov     dx,offset dpathfilenm   ;set to (*.*) ASCIIZ string
  83.             xor     cx,cx                   ;here, normal--change to include dirs
  84.             mov     ah,4EH                  ;Find First Matching File call
  85.         int    21h
  86.         jnc    gf2
  87.         jmp    gf_err_xit
  88.  
  89. gf2:
  90.                         ;check for leading dpath
  91.         mov     si,offset dpathfilenm-1
  92.             add     si,dpathfilenm_len
  93.             mov     cx,dpathfilenm_len
  94.             std                     ;reverse direction, parse from the end
  95.  
  96. gf3:
  97.         lodsb
  98.         cmp    al,'\'        ;end of path?
  99.         je    gf4
  100.         cmp    al,'/'        ;alternate path delimiter
  101.         je    gf4
  102.         cmp    al,':'        ;drive prefix?
  103.         je    gf4
  104.         loop    gf3
  105.         dec    si
  106.  
  107. ;this ptr two bytes before the file name?  Has word for KB buffer read count
  108.  
  109. gf4:        mov    fileptr,si
  110.  
  111. getnext2:                               ;enter here with next file name
  112. gf5:        mov    di,si        ;copy found file name 
  113.  
  114. ;psp_dta_fnamext        equ     9EH     ;9EH-A9H;file name.ext, no blanks (12 bytes)
  115. ;point to the filename.ext portion in the DTA
  116. ;       Mov     SI,Offset DTA+30
  117. ;       mov     si,psp_dta_fnamext
  118.  
  119.             mov     si,offset dta2+30
  120.             add     di,2                    ;back up to first char in file name
  121.             cld                             ;now forward direction
  122.  
  123. ;now xfer the found filename.ext and overlay the wildcard portion of the dpath..
  124.             mov     cx,13                   ;max len of fname.ext, incl ".", 0
  125.  
  126. gf6:        lodsb
  127.         stosb
  128.         cmp    al,0
  129.         loopne    gf6
  130.  
  131. ;note that length now has to be updated if used (dpathfilenm_len)
  132. gf7:          
  133.         sub    di,offset dpathfilenm+1
  134.         mov    dpathfilenm_len,di
  135.         
  136. ;        neg    cx
  137. ;        add    cx,13-1
  138. ;        mov    dpathfilenm_len,cx
  139.  
  140. gf8:
  141. ;insert test code to check file name:
  142.         mov     dx,offset dpathfilenm
  143.         mov     cx,dpathfilenm_len    ;length of string
  144.         mov     ah,40H            ;write to file/dev function 
  145.         mov     bx,1            ;write to std out
  146.         int     21H
  147.         mov    dx,offset newline
  148.         mov    ah,9h            ;print string function call
  149.         int    21h
  150.  
  151. gf_ok_xit:    
  152.         clc
  153.         ret
  154.  
  155. gf_err_xit:
  156.         push    ax            ;save error code
  157.         mov    dx,offset gf_msg
  158.         mov    ah,9h
  159.         int    21h
  160.         pop    ax
  161.         call    errmsg
  162.         stc
  163.         ret
  164.  
  165. getfirst    endp
  166.  
  167.